package engine.newUi
{
	import flash.events.MouseEvent;
	import newx.com.control.window.NxWindowEvent;
	import newx.com.control.radio.NxRadioGroup;
	import newx.com.control.window.NxWindow;
	import engine.net.mgr.SystemSender;
	/**
	 *GMCC评价逻辑 
	 * @author liuel
	 * 
	 */
	public class GmccOpinionLogic
	{
		private static var _self:GmccOpinionLogic;
		private var _ui:GmccOpinionUI;
		private var _opinionGroup			:NxRadioGroup;
		//附言
		private var postscript:String="";
		//评价的类型
		private var appraiseArr:Array=[];
		
		public static function getInstance():GmccOpinionLogic
		{
			if(_self == null)
			{
				_self = new GmccOpinionLogic();	
			}
			return _self;
		}
		public function GmccOpinionLogic()
		{
		}
		public function  Init():void
		{
			_ui = GmccOpinionUI.getInstance(); 	
			_opinionGroup = new NxRadioGroup([_ui.radio1,_ui.radio2,_ui.radio3]);
			_ui.input.maxChars =50;
		}
		public function	BeforeShow():void
		{
			_opinionGroup.selectdNxRadio =_ui.radio1;
			addEventListener();
		}
		public function	AfterHide():void
		{
			_ui.showlabel.text ="";
			_ui.input.text ="";
			removeEventListener();
		}
		private function addEventListener():void
		{
			_ui.windowBG.addEventListener(NxWindowEvent.WINDOW_CLOSE,oncloseHandle);
			_ui.okbtn.addEventListener(MouseEvent.CLICK,onSendHandle);
		}
		private function removeEventListener():void
		{
			_ui.windowBG.removeEventListener(NxWindowEvent.WINDOW_CLOSE,oncloseHandle);
			_ui.okbtn.removeEventListener(MouseEvent.CLICK,onSendHandle);
		}
		private function oncloseHandle(e:NxWindowEvent):void
		{
			_ui.hide();
		}
		private function onSendHandle(e:MouseEvent):void
		{
			send();
			_ui.hide();
		}
		public function set title(str:String):void
		{
			var startIndex:int = str.search(":");
			var showStr:String = str.substr(startIndex+1,str.length).replace("</font><br/>","");
			_ui.showlabel.htmlText = showStr;
		}
		/**
		 *设置可评价类型 
		 * @param arr
		 * 
		 */		
		public function set type(arr:Array):void
		{
			appraiseArr =arr;
		}
		private function send():void
		{
			var message:String="";
			message = appraiseArr[_opinionGroup.selectedIndex]; //评价类型
			postscript = _ui.input.text;   //附言
			SystemSender.getInstance().SendGMCCTOServer("#EXTE#voteRes#"+message+"#"+postscript);
		}
	}
}